package de.pernpas.calendar.servlet.event;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.pernpas.calendar.common.CalUtils;
import de.pernpas.calendar.controller.Controller;
import de.pernpas.calendar.entity.Event;
import de.pernpas.calendar.service.EventService;

public class UpdateEvent extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private final Logger log = Logger.getLogger(Controller.class.getName());
	
	public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException{
		doPost(req, res);
	}
	
	public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException{
		CalUtils cu = new CalUtils();
		Event event = EventService.updateEvent(
				Long.parseLong(req.getParameter("key")),
				cu.getDate(req.getParameter("date")),
				req.getParameter("location"),
				req.getParameter("name"), 
				req.getParameter("description"));
		log.fine("Event mit ID " + event.getKey().getId() + " angelegt.");
		res.sendRedirect("/detail.jsp?year=" + req.getParameter("year") + 
				"&month=" + req.getParameter("month") + 
				"&day=" + req.getParameter("day"));
	}

}
